home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / arexxtutorial / sholist / sholist.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  4KB  |  145 lines

  1. /*   ShoList.rexx -  updated for ARexx Revision 1.10 - 9-October-1989 */
  2.  
  3. /*      copyright 1989 Richard Lee Stockton and Gramma Software.      */
  4. /*    This code is freely distributable as long as this copyright     */
  5. /*   notice remains, unchanged, at the start of the code. Thank you.  */
  6.  
  7. /*  'rx ShoList ?' will show USAGE. Output may be redirected to file  */
  8. /*                  ie, 'rx ShoList >ram:ports p' writes a formatted  */
  9. /*                    textfile of the current ports to a file in ram. */
  10.  
  11.  
  12. /* If the support lib not found then quit helpfully. */
  13.  
  14. CALL ADDLIB('rexxsupport.library',0,-30,0)
  15. IF ~show('L',"rexxsupport.library") THEN
  16.   DO
  17.     SAY 'libs:rexxsupport.library is not available'
  18.     EXIT 10
  19.   END
  20.  
  21.  
  22. /* These are the USAGE strings we output if we see a '?', or a bad letter */
  23.  
  24. LF     = '0A'x
  25. USAGE1 = LF"  ARexx USAGE: rx ShoList [ACDFHILMPRSTVW?]"LF
  26. USAGE2 = ,
  27. " A=directories  C=clip list    D=devices      F=open files"LF,
  28. "H=handlers     I=interrupts   L=libraries    M=memory   P=ports"LF,
  29. "R=resources    S=semaphores   T=ready_tasks  V=volumes  W=waiting_tasks",
  30. LF || LF"                ShoList with no argument shows ALL"
  31.  
  32.  
  33.  
  34. /************************  Program starts here  **************************/
  35.  
  36.  
  37. /* get the argument from CLI and make it all caps. (ARG=PARSE ARG UPPER) */
  38.  
  39. ARG x
  40.  
  41.  
  42. /* if no argument, give 'em everything */
  43.  
  44. IF length(x)=0 THEN x = 'ACDFHILMPRSTVW'
  45.  
  46.  
  47. /* if '?', output USAGE stuff and die */
  48.  
  49. IF (x=='?') THEN DO
  50.                     SAY USAGE1
  51.                     SAY USAGE2
  52.                     EXIT 5
  53.                  END
  54.  
  55.  
  56. /* Take each letter in the argument, one at a time */
  57.  
  58. DO i=1 TO length(x)
  59.    y=substr(x,i,1)
  60.  
  61.  
  62. /* Select an appropriate title for this letter */
  63.  
  64.    SELECT
  65.        WHEN y='A' THEN title = 'Assigned Directories [DOS list]'
  66.        WHEN y='C' THEN title = 'Clips [AREXX list]'
  67.        WHEN y='D' THEN title = 'Device Drivers'
  68.        WHEN y='F' THEN title = 'Open Files [local]'
  69.        WHEN y='H' THEN title = 'Handlers [DOS list]'
  70.        WHEN y='I' THEN title = 'Interrupts'
  71.        WHEN y='L' THEN title = 'Libraries'
  72.        WHEN y='M' THEN title = 'MemoryList Items'
  73.        WHEN y='P' THEN title = 'Ports'
  74.        WHEN y='R' THEN title = 'Resources'
  75.        WHEN y='S' THEN title = 'Semaphores'
  76.        WHEN y='T' THEN title = 'Ready Tasks'
  77.        WHEN y='V' THEN title = 'Volumes [DOS list]'
  78.        WHEN y='W' THEN title = 'Waiting Tasks'
  79.        OTHERWISE
  80.          DO          /* Bad Letter in argument. Complain and die */
  81.            SAY
  82.            SAY '  Usage Error!'  USAGE1 ' --->' y '?'
  83.            SAY USAGE2
  84.            EXIT 10
  85.          END
  86.    END
  87.  
  88.  
  89. /* ARexx scans system lists. This is where the good stuff gets done. */
  90.  
  91.    IF ( (y='C') | (y='F') ) THEN list = show(y,,';')
  92.                             ELSE list = showlist(y,,';')
  93.  
  94.  
  95. /* everything below is just formatting and printing the list to the CLI */
  96. /* based on the longest name in the list, and the number of list items. */
  97.  
  98.    listlength=length(list)    /* length in characters of the whole list */
  99.    longest=0
  100.    j=1
  101.    items=0
  102.    position=1
  103.  
  104.    DO WHILE(position>0)      /* how many total and how long is longest? */
  105.        position=pos(';',list,j) /* <-- returns 0 when the list runs out */
  106.        IF((position-j)>longest) THEN longest=position-j
  107.        IF(position>0) THEN j=position+1
  108.        items=items+1
  109.    END
  110.    IF((listlength+1-j)>longest) THEN longest=listlength+1-j /* last item */
  111.  
  112.    columns = 77%(longest+2)           /* we assume an 80 column display */
  113.    position=1
  114.    count=0
  115.    j=1
  116.    line = ""
  117.    IF(listlength==0) THEN items=0
  118.    SAY '      -*-*-*-' items title  '-*-*-*-'
  119.    IF(listlength==0) THEN ITERATE         /* no list, go to next letter */
  120.    DO WHILE(position>0)
  121.        position=pos(';',list,j)
  122.        IF(position>0) THEN
  123.          DO
  124.            nextItem = ""
  125.            nextItem = left(substr(list,j,position-j),longest)
  126.            IF LENGTH(STRIP(nextItem))==0 THEN
  127.              nextItem = left("<blank>",longest)
  128.            line = line || nextItem || '  '
  129.            j = position + 1
  130.          END
  131.        ELSE line = line || left(substr(list,j),longest)
  132.        count = count + 1
  133.        IF(count=columns) THEN
  134.          DO
  135.            SAY line
  136.            count=0
  137.            line=""
  138.          END
  139.    END
  140.    IF(count>0) THEN SAY line        /* Only print when the line is full */
  141. END
  142. EXIT
  143.  
  144. /* end of ShoList.rexx */
  145.